<template>
    <div class="form-sty">
        <div class="form-title">
            <div class="span-radius"></div>城市排名
        </div>
        <div>
            <div style="height:470px;width: 450px;" ref="paixutuChart"></div>
        </div>
    </div>
</template>

<script setup>
import { onMounted, ref, getCurrentInstance,onUnmounted } from 'vue';
import * as echarts from 'echarts';


const citydata = ref(['北京', '上海', '广东', '深圳', '杭州', '成都', '重庆', '南京', '武汉', '西安'])
const bardata = ref([100, 90, 80, 70, 60, 50, 40, 30, 45, 76])



const paixutuChart = ref(null);

const initChart = () => {
    const myChart = echarts.init(paixutuChart.value);
    myChart.hideLoading();
    const myColor = ['#eb2100', '#eb3600', '#d0570e', '#d0a00e', '#34da62', '#00e9db', '#00c0e9', '#0096f3', '#33CCFF', '#33FFCC'];
    const option = {

    tooltip: {
        trigger: 'axis',
        show: false,
        axisPointer: { // 坐标轴指示器，坐标轴触发有效
            type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
        },
    },
    legend: {
        show:false
    },
    grid: {
        left: '3%',
        right: '10%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: [{
        splitLine: {
            show: false
        },
        type: 'value',
        show: false,
    }],
    yAxis: [{
        splitLine: {
            show: false
        },
        axisLine: { //y轴
            show: false
        },
        type: 'category',
        axisTick: {
            show: false
        },
        inverse: true,
        data: citydata.value,
        axisLabel: {
            color: '#A7D6F4',
            fontSize: 14,
        }
    }],
    series: [{
        name: '',
        type: 'bar',
        barWidth: 12, // 柱子宽度
        label: {
            show: true,
            position: 'right', // 位置
            color: '#A7D6F4',
            fontSize: 14,
            distance: 15, // 距离
			formatter: '{c}' // 这里是数据展示的时候显示的数据
        }, // 柱子上方的数值
        itemStyle: {
            normal: {
                    borderRadius: 30,
                    color: function (params) {
                        var num = myColor.length;
                        return myColor[params.dataIndex % num]
                    },
                }
        },
        data: bardata.value
    }, ]
    };
    myChart.setOption(option);
};


onMounted(async () => {
    initChart();

});

</script>

<style scoped>
/* 样式保持不变 */
@import "@/Css/index.css";
</style>